<?php

require '../com.swiss.mooh.dao.impl/FileDaoImpl.php';
require '../com.swiss.mooh.service/FileContentServiceImpl.php';


$dispatcher = new FileDaoImpl();
$fileContentService = new FileContentServiceImpl($dispatcher);

$output_dir = "../../assets/images/uploads/files/";

if (isset($_FILES["myfile"])) {
    $ret = array();

    $error = $_FILES["myfile"]["error"];
    //You need to handle  both cases
    //If Any browser does not support serializing of multiple files using FormData() 
    if (!is_array($_FILES["myfile"]["name"])) { //single file
        $fileName = $_FILES["myfile"]["name"];
        move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $fileName);

        $fileContentService->createNewFileContent(uniqid(), $fileName, $output_dir . $fileName, "", date('Y-m-d h:i:s a', time()));

        $ret[] = $fileName;
    }
    echo json_encode($ret);
}
